﻿using System;
using System.Windows;
using System.Windows.Controls;
using DeepEarth.Core;
using DeepEarth.Toolkit.Geometry.Data;
using DeepEarth.Toolkit.Geometry;
using System.Windows.Media;
namespace DeepEarth.Toolkit.Drawing
{
    public class LabelDrawProcessor : PointDrawProcessor
    {        
        public LabelDrawProcessor(UIElement interactionSurface, Panel drawingSurface, Func<Location, Point> locationToViewportPoint, Func<Point, Location> viewportPointToLocation)
            : base(interactionSurface, drawingSurface, locationToViewportPoint, viewportPointToLocation)
        {
            PositionOrigin = DeepEarth.Map.Core.PositionOrigin.Center;

            // TODO: The label control doesn't use the LabelGeometry at all. (Fix this!)

            label = new DeepEarth.Toolkit.Geometry.Label() { Text = DeepEarth.Toolkit.Geometry.Label.EmptyText };
            RenderedElement = label;
        }

        protected override void DrawComplete(Location l)
        {
            LabelGeometry pointGeometry = new LabelGeometry();
            pointGeometry.Position = l;

            SolidColorBrush scb = Stroke as SolidColorBrush;

            if (scb != null)
            {
                pointGeometry.TextColor = scb.Color;
            }

            OnDrawComplete(pointGeometry);
        }

        DeepEarth.Toolkit.Geometry.Label label;

        public Brush Stroke
        {
            get
            {
                if (label != null)
                {
                    return label.TextBrush;
                }
                return null;                
            }
            set
            {
                if (label != null && value != label.TextBrush)
                {
                    label.TextBrush = value;

                    //SolidColorBrush scb = label.TextBrush as SolidColorBrush;

                    //if (scb != null)
                    //{
                    //    byte alpha = scb.Color.A;

                    //    Color glowColor = Color.FromArgb(alpha, 0, 0, 0);
                    //    label.GlowBrush = new SolidColorBrush(glowColor);
                    //}
                    OnPropertyChanged("Stroke");
                }
            }
        }
    }
}
